﻿using BaseData.API.Read.Applications.Commands;
using BaseData.Domain;
using BaseData.ErrorCode;
using BaseData.Infrastructure.Interfaces;
using MediatR;

namespace BaseData.API.Read.Applications.CommandHandlers
{
    /// <summary>
    /// 绑定角色命令
    /// </summary>
    public class BindRoleCommandHandler : IRequestHandler<BindRoleCommand, ApiResult<List<Role>>>
    {
        private readonly IBaseRepository<Role> roleRep;

        public BindRoleCommandHandler(IBaseRepository<Role> roleRep)
        {
            this.roleRep = roleRep;
        }
        public Task<ApiResult<List<Role>>> Handle(BindRoleCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Role>> result= new ApiResult<List<Role>>();
            result.Code=ApiEnum.查询成功;
            result.Message=ApiEnum.查询成功.ToString();

            var list = roleRep.GetAll().Where(x => !x.IsDel).ToList();

            result.Data = list;

            return Task.FromResult(result);
        }
    }
}
